//
//  StatusCell.swift
//  SinaWeibo
//
//  Created by yang on 15/11/14.
//  Copyright © 2015年 yang. All rights reserved.
//

import UIKit
import SnapKit
let StatusCellMargin: CGFloat = 12
let StatusCellIconWitdth: CGFloat = 35

class StatusCell: UITableViewCell {
    var bottomConstraints: Constraint?
    var status :Status?{
        didSet{
            originalView.status = status
            self.bottomConstraints?.uninstall()
            if let re = status?.retweeted_status {
                reweetedStatusView.retweetedStatus = re
                reweetedStatusView.hidden = false
                bottomView.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints =  make.top.equalTo( reweetedStatusView.snp_bottom).constraint
                })
            }else{
                reweetedStatusView.hidden = true
                bottomView.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraints =  make.top.equalTo(originalView.snp_bottom).constraint
                })
            
            }
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style:style,reuseIdentifier:reuseIdentifier)
        selectionStyle = .None
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI(){
    contentView.addSubview(originalView)
    contentView.addSubview(bottomView)
    contentView.addSubview(reweetedStatusView)
        originalView.snp_makeConstraints { (make) -> Void in
        make.left.right.top.equalTo(contentView)
        }
        reweetedStatusView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.right.equalTo(originalView)
        }
        bottomView.snp_makeConstraints { (make) -> Void in
            make.left.right.equalTo(contentView)
          self.bottomConstraints =  make.top.equalTo( reweetedStatusView.snp_bottom).constraint
            make.height.equalTo(40)
        }
        contentView.snp_makeConstraints { (make) -> Void in
        make.bottom.equalTo(bottomView)
        make.top.left.right.equalTo(self)
        }
    }
    private lazy var originalView:StatusOriginalView = StatusOriginalView()
    private lazy var bottomView:StatusCellBottomView = StatusCellBottomView()
    private lazy var reweetedStatusView:ReweetedStatusView = ReweetedStatusView()
}
